package boot.service.impl;

import boot.dao.GoodsDao;
import boot.domain.Goods;
import boot.service.IGoodsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements IGoodsService {
    @Autowired
    private GoodsDao goodsDao;

    @Override
    public IPage<Goods> getPage(int currentPage, int pageSize) {
        IPage page=new Page(currentPage, pageSize);
        return goodsDao.selectPage(page, null);
    }

    @Override
    public IPage<Goods> getPage(int currentPage, int pageSize, Goods goods) {
        LambdaQueryWrapper<Goods> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(Strings.isNotEmpty(goods.getType()), Goods::getType, goods.getType());
        lambdaQueryWrapper.like(Strings.isNotEmpty(goods.getName()), Goods::getName, goods.getName());
        lambdaQueryWrapper.like(Strings.isNotEmpty(goods.getDesc()), Goods::getDesc, goods.getDesc());
        IPage page=new Page(currentPage, pageSize);
        return goodsDao.selectPage(page, lambdaQueryWrapper);
    }
}
